import SwiftUI

struct TabBarItem: Identifiable {
    let id = UUID()
    let icon: String
    let label: String
}

struct TabBar: View {
    @Binding var selectedIndex: Int
    let items: [TabBarItem]
    var body: some View {
        HStack {
            ForEach(Array(items.enumerated()), id: \ .element.id) { index, item in
                Button(action: { selectedIndex = index }) {
                    VStack(spacing: 4) {
                        Image(systemName: item.icon)
                            .font(.system(size: 22, weight: .semibold))
                            .scaleEffect(selectedIndex == index ? 1.2 : 1.0)
                            .foregroundColor(selectedIndex == index ? .accentColor : .gray)
                            .animation(.spring(response: 0.3, dampingFraction: 0.7), value: selectedIndex)
                        Text(item.label)
                            .font(.caption)
                            .foregroundColor(selectedIndex == index ? .accentColor : .gray)
                    }
                    .padding(.vertical, 8)
                    .frame(maxWidth: .infinity)
                }
            }
        }
        .background(.ultraThinMaterial)
        .clipShape(RoundedRectangle(cornerRadius: 18))
        .shadow(color: Color.black.opacity(0.04), radius: 8, x: 0, y: -2)
        .padding(.horizontal, 12)
        .padding(.bottom, 8)
    }
}

#Preview {
    @State var selected = 0
    return TabBar(selectedIndex: $selected, items: [
        TabBarItem(icon: "mappin.and.ellipse", label: "地点"),
        TabBarItem(icon: "calendar", label: "时间"),
        TabBarItem(icon: "location", label: "附近"),
        TabBarItem(icon: "square.and.arrow.up", label: "社媒")
    ])
} 